package com.thread.book.book2;

import org.junit.Test;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.function.IntBinaryOperator;

public class AtomicTest01 {
    public static void main(String[] args) throws InterruptedException {
        //原子操作
        AtomicInteger at = new AtomicInteger(2);
        //加2返回结果
        at.addAndGet(2);
        //如果预期值4等于原来的值,则更新为5
        at.compareAndSet(4, 5);
        //返回旧值,再加5
        at.getAndAdd(5);
        //返回旧值加一
        at.getAndIncrement();
        //返回旧值在设置为3
        at.getAndSet(3);
        System.out.println("===========" + at.get());
    }
}
